﻿package jakey.SalaryCount;

import jakey.SalaryCount.SQLite.dbHelper;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class PersonInfoActivity extends Activity {
	private String user_name;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.info);
		
		Button editbButton = (Button)findViewById(R.id.info_editBtn);
		editbButton.setOnClickListener(new EditBtnListener());
		
		Button gobackbButton = (Button)findViewById(R.id.info_gobackBtn);
		gobackbButton.setOnClickListener(new GobackBtnListener());
	}
	
	class GobackBtnListener implements OnClickListener  {

		public void onClick(View v) {
			// TODO Auto-generated method stub
			PersonInfoActivity.this.finish();
		}
		
	}
	
	class EditBtnListener implements OnClickListener {

		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent intent = new Intent();
			intent.putExtra("user_name", user_name);
			intent.setClass(PersonInfoActivity.this, PersonInfoEditActivity.class);
			PersonInfoActivity.this.startActivity(intent);
		}
		
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		
		Intent intent = this.getIntent();
		user_name = intent.getStringExtra("user_name");
		dbHelper dbHelper = new dbHelper(this, "salaryCount_db", null);
		Cursor cursor = dbHelper.select("user" , null, "user_name=?", new String[]{user_name}, null, null, null);
		while(cursor.moveToNext()) {
			int salary = cursor.getInt(cursor.getColumnIndex("salary"));
			String info = cursor.getString(cursor.getColumnIndex("info"));
			String major = cursor.getString(cursor.getColumnIndex("major"));
			
			TextView tv_name = (TextView)findViewById(R.id.info_name);
			tv_name.setText(user_name);
			
			TextView tv_salary = (TextView)findViewById(R.id.info_salary);
			tv_salary.setText(salary + "");
			
			TextView tv_major = (TextView)findViewById(R.id.info_major);
			tv_major.setText(major);
			
			TextView tv_info = (TextView)findViewById(R.id.info_info);
			tv_info.setText(info);
		}
		cursor.close();
		dbHelper.close();
	}
}
